/*
 表单提交方法
 * */
$('#sbt').on('click',function(){
	submitFun();
})
function submitFun(){
	$('.errorMessage').html('');
	var phone = Boolean($('#phone').val().trim());
	var pass = Boolean($('#password').val().trim());
	//var yanzheng = Boolean($('#vcode').val().trim());
	var tipPhone = '必须录入手机名。<br>';
	var tipPass = '必须录入密码。<br>';
	//var tipYanzheng = '必须录入验证码。';
	if(phone && pass){
		$('.errorMessage').hide();
		login($('#phone').val(),$('#password').val());
	}else{
		$('.errorMessage').show();
		if(!phone){
			$('.errorMessage').append(tipPhone);
		}
		if(!pass){
			$('.errorMessage').append(tipPass);
		}
	}
}

//获取验证码
function getYan(){
	$('.yan').attr('src','/captcha/code.html');
}
//更改验证码
function changeYan(){
	$('.yan').attr('src','/captcha/code.html');
}
$('.yan').on('click',function(){
	changeYan();
})
window.onload = function(){
	getYan();
}


//登录提交
function login(phone,password){
	$('#phone').val('');
	$('#password').val('');
	$.ajax({
		type : "POST",
		dataType : 'json',
		url : "/eshop/user/pcEshoploginAction.json",
		data : {
			"phone" : phone,
			"passWord" : password,
		},
		success : function(data) {
			if (data["code"] == 200) {
				var referer=$("#referer").val();
				var hiddenreturnUrl=$("#hiddenreturnUrl").val();
				if (hiddenreturnUrl!=null && hiddenreturnUrl!="") {
					location.href= hiddenreturnUrl;
				}
				if (referer!=null && referer!="") {
					location.href= referer;
				}else{
					location.href="/eshop/pcindex.html";
				}
			}else{
				$('.errorMessage').show();
				$('.errorMessage').html("手机号或密码错误!<br>");
				$("#password").val("");
				$("#password").focus();
			}
		}
	})
}

window.onscroll = function(){
	var top = document.documentElement.scrollTop || document.body.scrollTop;
	gotoTop(top);
	$('.gotoTop').on('click',function(){
		document.documentElement.scrollTop = 0;
		document.body.scrollTop = 0;
	})
}

function gotoTop(top){
	if(top > 450){
		//出现回到顶部箭头
		$('.gotoTop').show();
	}else{
		//隐藏回到顶部箭头
		$('.gotoTop').hide();
	}
}